#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int x[3],a1[N],a[N],c[N];
int main()
{
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a1[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>c[i];
	}
	string s;
	while(cin>>s)
	{
		if(s.size()==1)
			break;
	}
	int T;
	cin>>T;
	while(T--)
	{
		cin>>x[0]>>x[1]>>x[2]>>x[3];
		/*for(int i=1;i<=n;i++)
		{
			a[i]=a1[i] xor x[i%4];
		}
		for(int i=1;i<=n;i++)
		{
			cout<<a[i]<<' ';
		}
		cout<<endl;*/
		cout<<1<<endl;
	}
	return 0;
}
